package com.twohand.admin.Config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class VirtualPath implements WebMvcConfigurer {
    //文件保存位置
    @Value("${custom.saveStaticPath}")
    public String saveStaticPath;
    //静态访问路径
    @Value("${custom.staticPath}")
    public String staticPath;
    public final Logger log = LoggerFactory.getLogger(VirtualPath.class);
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("虚拟资源拦截："+staticPath);
        log.info("虚拟资源指向："+"file:"+saveStaticPath+staticPath);
        registry.addResourceHandler(staticPath+"**").addResourceLocations("file:"+saveStaticPath+staticPath);
    }
}
